#encoding=utf8
'''
Created on 2012-10-18

@author: Administrator
'''

from dispatch.Processor import Processor
from pub import Func, UserDict, RoomDict;
from pub.Config import Config
class RIFACClass(Processor):
    '''
    指令：RIFAC(room idiom found add check) 邀请游戏验证
    备注：反馈邀请
    格式：c-s:cmd#cmdId#roomId#userId#resultFlag#msg
     s-c:cmd#cmdId#roomId#userId#userIdTo#userIdToNickName#resultFlag#msg
    
    '''
    def __init__(self,):
        Processor.__init__(self,)
        self.__roomId = 0;
        self.__userId = 0;
        self.__flag = 0;
        self.__msg = "";
        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 4:      
            self.__roomId = Func.strToInt(cmdContent[0], Config.I_SYS_ZERO);
            self.__userId = Func.strToInt(cmdContent[1], Config.I_SYS_ZERO);
            self.__flag = Func.strToInt(cmdContent[2], Config.I_SYS_ZERO);            
            self.__msg = Func.toStr(cmdContent[3], Config.I_SYS_ZERO);            
            return True;        
        return False;
    def outData(self,):
        room = RoomDict.getRoomFromDictById(self.__roomId);
        if not room:
            return False;
        user = UserDict.getUserFromUserDictById(self.__userId);
        userOwner = room.get_room_owner();
        if not userOwner:
            return False;
        if not user:
            return False;
        if self.__flag:#通过邀请
            user.set_room(room);
            user.set_user_state(Config.I_USER_GAME_STATE_OK);            
            RoomDict.addOrModUserToRoom(user, self.__roomId);
        
        sendData = [];
        sendData.append(self.__roomId);
        sendData.append(userOwner.get_user_id());
        sendData.append(self.__userId);
        sendData.append(user.get_user_name());
        sendData.append(self.__flag);
        sendData.append(self.__msg);
        sendStr = self.setPackage(sendData);
        RoomDict.sendInfoToRoomAllUser(roomObj=room, cmd="", msg=sendStr, isPackage=False);
        return True;
            
        
        
        
